package com.fan.leetcode;

import org.junit.jupiter.api.Test;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * 剑指 Offer 10- I. 斐波那契数列
 *
 * @author ZhangFan
 * @since 2021/9/4 下午 1:03
 */
public class QuestionOffer10_I {
    @Test
    void test() {
        System.out.println("fib(n) = " + fib(95));
    }

    public int fib(int n) {
        LinkedList<Long> list = new LinkedList<>();
        for (int i = 0; i <= n; i++) {
            if (i < 2) {
                list.addLast((long) i);
            } else {
                list.addLast((list.getFirst() + list.getLast()) % 1000000007);
                list.removeFirst();
            }
        }
        return (int) (list.getLast() % 1000000007);
    }
}
